<!--
 * @Description: In User Settings Edit
 * @Author: your name
 * @Date: 2019-07-30 20:02:30
 * @LastEditTime: 2020-02-28 11:25:38
 * @LastEditors: Please set LastEditors
 -->
<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title></title>
    <link rel="stylesheet" type="text/css" href="../css/vant.css">
    <link rel="stylesheet" type="text/css" href="../css/base.css" />
    <script type="text/javascript" src="../script/vue.min.js"></script>
    <script type="text/javascript" src="../script/vant.min.js"></script>
    <script type="text/javascript" src="../script/base.js"></script>
    <script type="text/javascript" src="../script/jquery.js"></script>
    <script type="text/javascript" src="../script/layer/mobile/layer.js"></script>
    <style type="text/css">
        .content {
            display: flex;
            flex-direction: column;
            height: 100vh;
        }

        /* .van-field__label {
            width: auto;
        } */

        .bottomBtn {
            height: 50px;
            width: 100%;
            padding: 0 10px;
            display: flex;
            margin: auto auto 10px auto;
        }

        .bottomBtn .van-button {
            flex: 1;
            margin: 0 10px;
        }
    </style>
</head>

<body>
    <div id="app" v-cloak>
        <div class="box">
            <van-nav-bar :title="name + '明细'" id="safeTop" left-arrow @click-left="onClickLeft"></van-nav-bar>
            <div class="content">
                <van-field v-model="formData.ProductName" label="产品名称：" label-width="11vw" placeholder="请填写产品名称"
                    readonly></van-field>
                <van-field v-model="formData.Batch" label="批次：" placeholder="请填写批次" label-width="11vw" readonly>
                </van-field>
                <van-field v-model="formData.JNo" label="上架号：" placeholder="请填写上上架号" label-width="11vw" readonly>
                </van-field>
                <van-field v-model="api.pageParam.SJNo" label="上架层数：" placeholder="请填写上架层数" label-width="11vw" readonly>
                </van-field>
                <van-field v-model="formData.GSStartDate" label="开始灌酸时间：" label-width="11vw" placeholder="请填写开始灌酸时间"
                    readonly></van-field>
                <van-field v-model="formData.GSSEndDate" label="结束灌酸时间：" label-width="11vw" placeholder="请填写结束灌酸时间"
                    readonly></van-field>
                <van-field v-model="formData.KJDate" v-show="name == '抽酸'" label="开机时间：" label-width="11vw"
                    placeholder="请填写开机时间" readonly>
                </van-field>
                <van-field v-model="formData.CSYJDate" label="可抽酸时间：" placeholder="请填写可抽酸时间" label-width="11vw"
                    readonly></van-field>
                <van-field v-model="formData.CSDate" label="抽酸时间：" placeholder="请填写抽酸时间" label-width="11vw" readonly>
                </van-field>
                <van-field v-model="formData.DDTime" label="结束抽酸时间：" label-width="11vw" placeholder="请填写结束抽酸时间"
                    readonly></van-field>
                <van-field v-model="formData.GMYJDate" v-show="name == '下架'" label=" 可下架时间：" placeholder="请填写可抽酸时间"
                    label-width="11vw" readonly></van-field>
                <van-field v-model="formData.GMDate" v-show="name == '下架'" label="下架时间：" label-width="11vw"
                    placeholder="请填写下架时间" readonly>
                </van-field>
                <div class="bottomBtn">
                    <van-button size="small" type="danger" v-show="name == '抽酸' && !formData.CSDate"
                        @click="handlerAdd">抽 &nbsp &nbsp &nbsp &nbsp 酸</van-button>
                    <!-- <van-button size="small" type="danger" @click="handlerEnd">结束抽酸</van-button> -->
                    <van-button size="small" type="danger" v-show="name == '抽酸' &&formData.CSDate&&!formData.DDTime"
                        @click="handlerEnd">结束抽酸</van-button>
                    <van-button size="small" type="danger" v-show="name == '下架' && !formData.GMDate"
                        @click="handlerAdd">确定下架</van-button>

                    <!-- <van-button size="small" type="info" @click="confirm" >提交
                    </van-button> -->
                </div>
            </div>
            <audio id="audioPlayer" preload="auto">
                <source src="../image/aigei_com.mp3" type="audio/mpeg">
            </audio>
            <div class="indexBottom">
                汇智云创 技术支持
            </div>
        </div>
    </div>
</body>

<script type="text/javascript">
    var vm;
    apiready = function () {


        vm = new Vue({
            el: '#app',
            data: {
                name: api.pageParam.name,
                formData: {
                    JNo: '',
                    ProductName: '',
                    Batch: '',
                    Qty: '',
                    GSStartDate: '',
                    GSSEndDate: '',
                    KJDate: '',
                    CSYJDate: '',
                    CSDate: '',
                    GMYJDate: '',
                    GMDate: '',
                    DDTime: '',
                    GSID: '',
                },
            },
            created: function () {
                var that = this;
                window.localStorage.setItem('pageName', JSON.stringify(that.name))

                if (api.pageParam.MonitorID) {
                    var cmd
                    that.name == '抽酸' ? cmd = 'getCSDetail' : cmd = 'getGMDetail'
                    var obj = {
                        MonitorID: api.pageParam.MonitorID,
                        SJNo: api.pageParam.SJNo
                    }
                    APP.ajax(cmd, obj, function (res) {
                        console.log('res', JSON.stringify(res.ds))
                        if (res.ds.length) {
                            res.ds.map((item) => {
                                item.GSStartDate = item.GSStartDate ? item.GSStartDate.replace('T', ' ') : ''
                                item.GSSEndDate = item.GSSEndDate ? item.GSSEndDate.replace('T', ' ') : ''
                                item.CSDate = item.CSDate ? item.CSDate.replace('T', ' ') : ''
                                item.KJDate = item.KJDate ? item.KJDate.replace('T', ' ') : ''
                                item.DDTime = item.DDTime ? item.DDTime.replace('T', ' ') : ''

                            })
                            that.formData = res.ds[0]
                            that.formData.DDTime = res.ds[0].DDTime
                        }
                    })
                }

            },
            mounted() {
                APP.setSafeTop()
                APP.keyBoardChange()
            },
            methods: {
                handlerEnd() {
                    var that = this

                    api.confirm({
                        title: '提示',
                        msg: '是否确认提交！',
                        buttons: ['确定', '取消']
                    }, function (ret, err) {
                        if (ret.buttonIndex == 1) {
                            that.formData.DDTime = APP.getFormatDate(new Date())
                            api.toast({
                                msg: '结束抽酸时间：' + that.formData.DDTime
                            })
                            setTimeout(() => {
                                that.confirm()
                            }, 1000);
                        }
                        else {
                            api.toast({
                                msg: '提交已取消!'
                            })

                        }
                    });

                },
                handlerAdd() {
                    var that = this
                    api.confirm({
                        title: '提示',
                        msg: '是否确认提交！',
                        buttons: ['确定', '取消']
                    }, function (ret, err) {
                        if (ret.buttonIndex == 1) {
                            if (that.name == '抽酸') {
                                that.formData.CSDate = APP.getFormatDate(new Date())
                                api.toast({
                                    msg: '抽酸时间：' + that.formData.CSDate
                                })
                            } else {
                                that.formData.GMDate = APP.getFormatDate(new Date())
                                api.toast({
                                    msg: '下架时间：' + that.formData.GMDate
                                })
                            }
                            setTimeout(() => {
                                that.confirm()
                            }, 1000);
                        }
                        else {
                            api.toast({
                                msg: '提交已取消!'
                            })

                        }
                    });


                },
                confirm() {
                    var that = this
                    var obj, cmd
                    if (that.name == '抽酸') {
                        cmd = 'saveCSRecord'
                        obj = {
                            MonitorID: api.pageParam.MonitorID,
                            CSDate: that.formData.CSDate,
                            CSEndDate: that.formData.DDTime,
                            GSID: that.formData.GSID,
                            SJNo: api.pageParam.SJNo
                        }
                    }
                    else {
                        cmd = 'saveGMRecord'
                        obj = {
                            MonitorID: api.pageParam.MonitorID,
                            GMDate: that.formData.GMDate,
                            GSID: that.formData.GSID,
                            SJNo: api.pageParam.SJNo
                        }
                    }

                    console.log('180obj', JSON.stringify(obj))
                    APP.ajax(cmd, obj, function (res) {
                        console.log('res', JSON.stringify(res))
                        api.toast({
                            msg: '提交成功！'
                        })
                        api.sendEvent({
                            name: 'refreshExtraAcidList'
                        })
                    })

                },

                onClickLeft() {
                    var that = this
                    api.closeWin()
                },
            }
        })
    };
</script>

</html>